package com.qfedu.vhr.controller.sys;

import com.qfedu.vhr.common.RespBean;
import com.qfedu.vhr.system.entity.Position;
import com.qfedu.vhr.system.service.IPositionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author baize
 * @date 2023/1/10
 * @site www.qfedu.com
 */
@RestController
@RequestMapping("/system/basic/position")
public class PositionController {

    @Autowired
    IPositionService positionService;

    @GetMapping("/")
    public List<Position> getAll() {
        return positionService.list();
    }

    @PostMapping("/")
    public RespBean addPosition(@RequestBody Position position) {
        return positionService.addPosition(position);
    }

    @DeleteMapping("/{pid}")
    public RespBean deletePosistionById(@PathVariable Integer pid) {
        return positionService.removeById(pid) ? RespBean.ok("删除成功") : RespBean.error("删除失败");
    }

    @PutMapping("/")
    public RespBean updatePosition(@RequestBody Position position) {
        return positionService.updatePosition(position);
    }


    @GetMapping("/{id}")
    public Position getPositionById(@PathVariable Integer id) {
        return positionService.getById(id);
    }
}
